package web.mb;

import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import metier.entities.Cms;
import metier.entities.Devise;
import metier.entities.Nouvelle;
import metier.sess.ICmsLocal;

@ManagedBean
@RequestScoped
public class CmsMB {

	@EJB
	private ICmsLocal metierc;

	private Integer Id;
	private Cms cms = new Cms();

	public Integer getId() {
		return Id;
	}

	public void setId(Integer id) {
		Id = id;
	}

	public Cms getCms() {
		return cms;
	}

	public void setCms(Cms cms) {
		this.cms = cms;
	}

	public String Ajouter() {

		metierc.addCms(cms);
		return "ManageCms.xhtml";
	}

	public String edit(Integer Id) {
		this.Id = Id;
		Cms d = metierc.getCms(Id);
		this.cms.setTitle(d.getTitle());
		this.cms.setDescription(d.getDescription());
		return "EditCms.xhtml";
	}

	public String view(Integer Id) {
		this.Id = Id;
		Cms d = metierc.getCms(Id);
		this.cms.setTitle(d.getTitle());
		this.cms.setDescription(d.getDescription());
		return "ViewCms.xhtml";
	}

	public String Modifier() {
		Cms d = metierc.getCms(Id);

		d.setTitle(cms.getTitle());
		d.setDescription(cms.getDescription());
		metierc.updateCms(d);
		return "ManageCms.xhtml";	
	}

	public String Supprimer(Integer Id) {
		metierc.deleteCms(Id);
		return "succes";
	}

	public List<Cms> getListCmss() {
		return metierc.getAllCms();
	}

}
